<?php
/**
 * Author Yulin
 * Email  dwzhanglong@126.com
 * Date   2017-7-21
 * Func   彩票趋势
 */
defined('IN_YuLin') || exit('NO PERMIT!');

//	彩种
$lottery = [];
$tmp = $db->getall('SELECT * FROM '.Table('lottery').' WHERE status = 1 ORDER BY id');
foreach($tmp as $val)
{
	$lottery[$val['id']] = $val;
}

//	记录
$id = intval($_GET['id']);
!array_key_exists($id,$lottery) && $id = $tmp[0]['id'];	//	默认彩票

//	开奖记录
$data = $db->getall('SELECT * FROM '.Table('lottery_period').' WHERE cid = '.$id.' AND rednum <> \'\' ORDER BY stoptime DESC LIMIT 50');
foreach($data as $key => $val)
{
	//	开奖号
	$val['rednum'] = explode(',',$val['rednum']);
	foreach($val['rednum'] as $key2 => $val2)
	{
		$val['rednum'][$key2] = intval($val2);	//	01,02这样的转成1,2
	}
	
	//	计算遗漏
	$tmp = $db->getrow('SELECT * FROM '.Table('lottery_period_yilou').' WHERE iid = '.$val['id']);
	$val['yilou'][] = $tmp['data_0'] ? explode(',',$tmp['data_0']) : [];
	$val['yilou'][] = $tmp['data_1'] ? explode(',',$tmp['data_1']) : [];
	$val['yilou'][] = $tmp['data_2'] ? explode(',',$tmp['data_2']) : [];
	$val['yilou'][] = $tmp['data_3'] ? explode(',',$tmp['data_3']) : [];
	$val['yilou'][] = $tmp['data_4'] ? explode(',',$tmp['data_4']) : [];
	
	$data[$key] = $val;
}

$tpl->display('wap/trend');